package cn.iocoder.yudao.position.controller.admin;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.position.entity.PositionCategoryDO;
import cn.iocoder.yudao.position.service.PositionCategoryService;
import cn.iocoder.yudao.position.vo.PositionCategoryTreeNodeVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "APP - 字典-行业类别表(树形结构)")
@RestController
@RequestMapping("/app/position/category")
@Validated
public class AppPositionCategoryController {

    @Resource
    private PositionCategoryService positionCategoryService;


    @GetMapping("/tree")
    @Operation(summary = "获取行业类别树形结构")
    @PermitAll
    @TenantIgnore
    public CommonResult<List<PositionCategoryTreeNodeVO>> getCategoryTree() {
        List<PositionCategoryDO> categories = positionCategoryService.getList();
        List<PositionCategoryTreeNodeVO> tree = positionCategoryService.buildCategoryTree(categories);
        return success(tree);
    }
}